﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using SmartSpace.Core;
using SmartSpace.Data;
using SmartSpace.Workflow;
using System.Data.Entity.Migrations;

namespace SmartSpace.Framework
{
    public class FrameworkDbContext : DbContext
    {
        public FrameworkDbContext()
            : base("name=" + SmartSpace.Configuration.ConnectionStringName)
        {
            Database.SetInitializer<FrameworkDbContext>(new MigrateDatabaseToLatestVersion<FrameworkDbContext, DBMC>());
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            DataContext.Build(modelBuilder);
            WorkflowContext.Build(modelBuilder);

            base.OnModelCreating(modelBuilder);
        }
    }

    internal sealed class DBMC : DbMigrationsConfiguration<FrameworkDbContext>   
    {
        public DBMC()   
        {   
            AutomaticMigrationsEnabled = true;   
            AutomaticMigrationDataLossAllowed = true;   
        }   
    }
}
